module;
#include <type_traits>
#include <exception>
#include <string>
export module mtry;

import expected;

export
template < typename F
    , typename Ret = typename std::invoke_result<F()>::type
    , typename Exp = expected<Ret, std::exception_ptr>
>
Exp mtry(F f)
{
    try {
        return Exp::success(f());
    }
    catch (...) {
        return Exp::error(std::current_exception());
    }
}


